﻿using BCCommon;
using BCDto.TMS.SystemProtocolConfig;
using BCService.TMS.SystemProtocolConfig;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.TMS.SystemProtocolConfig
{


    /// <summary>
    /// 系统协议配置接口
    /// </summary> 
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class SystemProtocolConfigController : ManagementBaseController
    {
        #region var
        private ISystemProtocolConfigService systemProtocolConfigService;
        #endregion


        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public SystemProtocolConfigController(ISystemProtocolConfigService systemProtocolConfigService)
        {
            this.systemProtocolConfigService = systemProtocolConfigService;
        }
        #endregion

        #region POST 添加  
        /// <summary>
        /// 添加新系统协议配置纪录
        /// </summary>
        /// <param name="dto">系统协议配置数据模型</param>
        /// <returns></returns>
        [Log("添加新系统协议配置纪录")]
        [HttpPost]
        [ProducesResponseType(typeof(SystemProtocolConfigDto), 200)]
        public IActionResult Post([FromBody] SystemProtocolConfigRequestDto dto)
        {
            var a = systemProtocolConfigService.Add(dto, this.Admin);
            return Ok(a);
        }

        #endregion

        #region PUT 修改   
        /// <summary>
        /// 修改系统协议配置纪录
        /// </summary>
        /// <param name="dto">系统协议配置数据模型</param>
        /// <returns></returns>
        [Log("修改系统协议配置纪录")]
        [HttpPut]
        [ProducesResponseType(typeof(SystemProtocolConfigDto), 200)]
        public IActionResult Put([FromBody] SystemProtocolConfigDto dto)
        {
            var a = Ok(systemProtocolConfigService.Update(dto, this.Admin));
            return a;
        }
        #endregion

        #region 删除  
        /// <summary>
        /// 删除系统协议配置纪录
        /// </summary>
        /// <param name="systemProtocolConfigKey">系统协议配置ID</param>
        /// <returns></returns>
        [Log("删除系统协议配置纪录")]
        [HttpDelete("{system_protocol_config_key}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "system_protocol_config_key")] string systemProtocolConfigKey)
        {
            systemProtocolConfigService.Delete(systemProtocolConfigKey);
            return NoContent();
        }
        #endregion

        #region GetByID     
        /// <summary>
        /// 获取一条系统协议配置纪录
        /// </summary>
        /// <param name="systemProtocolConfigKey">系统协议配置ID</param>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpGet("{system_protocol_config_key}")]
        [ProducesResponseType(typeof(SystemProtocolConfigDto), 200)]
        public IActionResult Get([FromRoute(Name = "system_protocol_config_key")] string systemProtocolConfigKey)
        {
            return (Ok(systemProtocolConfigService.GetById(systemProtocolConfigKey)));

        }
        #endregion

        #region Query 
        /// <summary>
        /// 查询系统协议配置
        /// </summary>
        /// <param name="protocolTitle">协议标题</param>
        /// <param name="protocolContent">协议内容</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns> 
        [AllowAnonymous]
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<SystemProtocolConfigDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name ="protocol_title")]string protocolTitle,
            [FromQuery(Name ="protocol_content")]string protocolContent,
            [FromQuery(Name = "index")] int? pageIndex = 1,
            [FromQuery(Name = "size")] int? pageSize = 10)
        {
            var a = Ok(systemProtocolConfigService.GetList(protocolTitle,protocolContent,pageIndex.Value, pageSize.Value));
            return a;
        }
        #endregion
    }

}
